﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Xml.Linq;
using System.Collections.Generic;

using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;
using YouHP.Utility;

namespace web.admin
{
    public partial class RecommendedUserAdd : System.Web.UI.Page
    {
        private RecommendUserBLL recommendUserBLL = RecommendUserBLL.Instance;
        private DiseaseBLL diseaseBll = DiseaseBLL.Instance;
        public List<string> diseaseSortList;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<DiseaseInfo> diseaseInfo;
                //DiseaseInfo tempDiseaseInfo = new DiseaseInfo();
                //tempDiseaseInfo.Name = "其他";
                diseaseInfo = diseaseBll.GetAllDisease();
                //diseaseInfo.Add(tempDiseaseInfo);
                DropDownList diseaseDownList = (DropDownList)(((DetailsView)recommendedUserInfo).FindControl("DiseaseDownList"));
                /*
                   foreach (DiseaseInfo item1 in diseaseInfo)
                   {
                       diseaseSortList.Add(item1.Name);
                   }
                 */
                diseaseDownList.DataSource = diseaseInfo;
                diseaseDownList.DataTextField = "Name";
                //disDownList.DataValueField = "Id";
                diseaseDownList.DataBind();
            }
        }

        protected void CancelButton_click(object sender, EventArgs e)
        {

        }
        protected void InsertButton_click(object sender, EventArgs e)
        {
            RecommendUserInfo info = validateForm(this.recommendedUserInfo);

            if (info != null)
            {
                if (recommendUserBLL.RecommendUserAdd(info))
                {
                    Response.Redirect("RecommendedUserList.aspx");
                }
            }
            else
            {
                Response.Write("<script>alert('User is not exist');</script>");
            }

        }
        protected void DataBound(object sender, EventArgs e)
        {

        }
        private RecommendUserInfo validateForm(DetailsView formViewCtl)
        {
            RecommendUserInfo info = new RecommendUserInfo();
            bool userIsExist = false;
            //info.IsNews = Convert.ToInt32(this.GroupId.Text);
            info.username = ((TextBox)formViewCtl.FindControl("用户名")).Text.Trim();
            info.diseasename = ((DropDownList)formViewCtl.FindControl("DiseaseDownList")).SelectedItem.Text;
            userIsExist=UserBLL.Instance.CheckExsitUserName(info.username);
            if ((userIsExist))
            {
                return info;
            }
            else
            {
                return (RecommendUserInfo)null;
            }
        }
    }
}
